<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="./plugins/layui/css/layui.css" media="all">
    <!-- <link rel="stylesheet" href="./build/css/app.css" media="all"> -->
    <style>
        /** kit_admin-v1.0.8 MIT License By http://kit/zhengjinfan.cn e-mail:zheng_jinfan@126.com */

        .kit-sided .layui-side-scroll .layui-nav-item a,
        .layui-layout-admin .layui-header .layui-layout-right {
            padding: 0
        }

        .kit-table,
        .kit-table-header {
            position: relative;
            box-shadow: 0 1px 7px 0 #ccc
        }

         ::-webkit-scrollbar {
            width: 10px;
            height: 10px
        }

         ::-webkit-scrollbar-button:vertical {
            display: none
        }

         ::-webkit-scrollbar-corner,
         ::-webkit-scrollbar-track {
            background-color: #e2e2e2
        }

         ::-webkit-scrollbar-thumb {
            border-radius: 0;
            background-color: rgba(0, 0, 0, .3)
        }

         ::-webkit-scrollbar-thumb:vertical:hover {
            background-color: rgba(0, 0, 0, .35)
        }

         ::-webkit-scrollbar-thumb:vertical:active {
            background-color: rgba(0, 0, 0, .38)
        }

        .kit-nav .layui-this,
        .layui-layout-left .layui-nav-item:hover {
            background-color: #393D49!important
        }

        .kit-layout-admin .kit-logo-mobile {
            display: none
        }

        .kit-nav .layui-nav-item {
            line-height: 50px
        }

        .kit-nav .layui-nav-item .layui-nav-more {
            top: 22px
        }

        .kit-nav .layui-nav-item .layui-nav-mored {
            top: 16px
        }

        .kit-nav .layui-nav-item .layui-nav-child {
            top: 55px
        }

        .kit-nav * {
            font-size: 13px
        }

        .kit-nav .layui-nav-bar {
            height: 0
        }

        .kit-nav .layui-this:after {
            content: none
        }

        .kit-layout-admin .layui-footer {
            height: 35px;
            line-height: 35px
        }

        .kit-layout-admin .layui-body {
            bottom: 35px;
            top: 50px
        }

        .kit-layout-admin .layui-header {
            height: 50px
        }

        .kit-layout-admin .layui-logo {
            line-height: 50px
        }

        .kit-layout-admin .kit-side {
            top: 50px
        }

        .kit-layout-admin .kit-sided {
            width: 50px
        }

        .kit-side .layui-side-scroll,
        .kit-side .layui-side-scroll .layui-nav-tree {
            width: auto
        }

        .kit-side .layui-side-scroll .kit-side-fold {
            height: 35px;
            background-color: #4A5064;
            color: #aeb9c2;
            line-height: 35px;
            text-align: center;
            cursor: pointer
        }

        .kit-sided .layui-side-scroll .layui-nav-item {
            text-align: center
        }

        .kit-sided .layui-side-scroll a span {
            display: none
        }

        .kit-layout-admin .kit-body-folded,
        .kit-layout-admin .kit-footer-folded {
            left: 50px
        }

        .kit-table-header {
            height: 50px
        }

        .kit-table-header .kit-search-btns {
            padding: 10px;
            position: absolute
        }

        .kit-table-header .kit-search-inputs {
            position: absolute;
            right: 70px;
            top: 0;
            padding: 10px 25px 10px 10px
        }

        .kit-table-header .kit-search-inputs .kit-search-keyword {
            margin-right: 10px;
            position: relative
        }

        .kit-table-header .kit-search-inputs .kit-search-more {
            cursor: pointer;
            color: #009688;
            position: absolute;
            top: 15px;
            right: -50px
        }

        .kit-table-header .kit-search-inputs .kit-search-keyword input {
            height: 30px;
            line-height: 30px;
            width: 200px;
            padding-right: 32px
        }

        .kit-table-header .kit-search-inputs .kit-search-keyword button {
            position: absolute;
            right: 0;
            top: 0;
            width: 30px;
            height: 30px;
            border: 0;
            cursor: pointer;
            background-color: #009688;
            color: #fff
        }

        .kit-table-header .kit-search-btns .layui-btn {
            padding: 0 15px
        }

        .kit-search-mored {
            width: 100%;
            height: auto;
            top: 51px;
            background-color: #fff;
            z-index: 5;
            box-shadow: 0 4px 7px -3px #ccc;
            position: absolute;
            margin-bottom: 10px;
            display: none
        }

        .kit-search-mored .kit-search-body {
            padding: 10px 10px 45px
        }

        .kit-search-mored .kit-search-footer {
            height: 50px;
            bottom: 0;
            left: 0;
            position: absolute;
            width: 100%;
            border-top: 1px solid #e2e2e2;
            text-align: right
        }

        .kit-tab,
        .kit-table-body {
            position: relative
        }

        .kit-search-mored .kit-search-footer .kit-btn {
            margin: 10px 5px;
            padding: 0 15px
        }

        .kit-search-mored .kit-search-footer .kit-btn:last-child {
            margin-right: 15px
        }

        .kit-tab,
        .kit-table-body .layui-table-view {
            margin: 0
        }

        .kit-tab {
            border-bottom: 0;
            box-shadow: none
        }

        .kit-tab .kit-tab-tool,
        .kit-tab .kit-tab-tool-body .kit-line {
            border-bottom: 1px solid #e2e2e2
        }

        .kit-tab .kit-tab-tool {
            position: absolute;
            width: 60px;
            height: 40px;
            top: 0;
            right: 10px;
            border-left: 1px solid #e2e2e2;
            line-height: 40px;
            text-align: center;
            cursor: pointer;
            border-right: 1px solid #e2e2e2
        }

        .kit-tab .kit-tab-tool:hover {
            background-color: #f3f3f3
        }

        .kit-tab .kit-tab-tool-body {
            position: absolute;
            top: 40px;
            right: 10px;
            width: 150px;
            border: 1px solid #e2e2e2;
            display: none;
            background-color: #fff;
            z-index: 999
        }

        .kit-tab .kit-tab-tool-body ul {
            text-align: center;
            padding: 8px 0
        }

        .kit-tab .kit-tab-tool-body ul li.kit-item {
            line-height: 35px;
            cursor: pointer;
            color: #393D49
        }

        .kit-tab .kit-tab-tool-body ul li.kit-item:hover {
            background-color: #f3f3f3
        }

        .kit-tab .layui-tab-title {
            width: calc(100% - 71px);
            padding-right: 0;
            position: absolute;
            z-index: 2
        }

        .kit-tab .layui-tab-content {
            padding: 0;
            position: relative;
            top: 41px;
            overflow-y: auto
        }

        .kit-tab .layui-tab-content iframe {
            width: 100%;
            border: 0
        }

        @media screen and (max-width:950px) {
            .kit-layout-admin .layui-body,
            .kit-layout-admin .layui-footer,
            .kit-layout-admin .layui-layout-left {
                left: 50px
            }

            .kit-layout-admin .kit-side {
                width: 50px
            }

            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item,
            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item dl dd {
                text-align: center
            }

            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item a,
            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item dl dd a {
                padding: 0
            }

            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item a span,
            .kit-layout-admin .kit-side .layui-side-scroll .layui-nav li.layui-nav-item dl dd a span,
            .kit-layout-admin .layui-logo,
            .kit-side .layui-side-scroll .kit-side-fold {
                display: none
            }

            .kit-layout-admin .kit-logo-mobile {
                display: block;
                width: 50px
            }
        }
    </style>
</head>

<body>
    <div class="kit-table">
        <div class="layui-form" lay-filter="kit-search-form">
            <div class="kit-table-header">
                <div class="kit-search-btns layui-btn-group demoTable">
                    <a href="javascript:;" data-action="add" class="layui-btn layui-btn-small"><i class="layui-icon"></i> 新增</a>
                    <a href="javascript:;" data-action="del-bulk" class="layui-btn layui-btn-small layui-btn-danger"><i class="layui-icon"></i> 批量删除</a>
                    <button class="layui-btn layui-btn-small" data-type="getCheckData">获取选中行数据</button>
                    <button class="layui-btn layui-btn-small" data-type="getCheckLength">获取选中数目</button>
                    <button class="layui-btn layui-btn-small" data-type="isAll">验证是否全选</button>
                </div>
                <div class="kit-search-inputs">
                    <div class="kit-search-keyword">
                        <input type="text" class="layui-input" name="keyword" placeholder="搜索关键字..">
                        <button lay-submit="" lay-filter="search"><i class="layui-icon"></i></button>
                    </div>
                    <div class="kit-search-more" id="kit-search-more">更多筛选<i class="layui-icon"></i></div>
                </div>
            </div>
        </div>
        <form class="layui-form" lay-filter="kit-search-form">
            <div class="kit-search-mored layui-anim layui-anim-upbit" style="display: none;">
                <div class="kit-search-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">输入框</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">验证手机</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">验证邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">范围</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="price_min" placeholder="￥" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="price_max" placeholder="￥" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">单行选择框</label>
                        <div class="layui-input-block">
                            <select name="interest" lay-filter="aihao">
                                <option value=""></option>
                                <option value="0">写作</option>
                                <option value="1" selected="">阅读</option>
                                <option value="2">游戏</option>
                                <option value="3">音乐</option>
                                <option value="4">旅行</option>
                              </select>
                            <div class="layui-unselect layui-form-select">
                                <div class="layui-select-title"><input type="text" placeholder="请选择" value="阅读" readonly="" class="layui-input layui-unselect">
                                    <i class="layui-edge"></i>
                                </div>
                                <dl class="layui-anim layui-anim-upbit">
                                    <dd lay-value="" class="layui-select-tips">请选择</dd>
                                    <dd lay-value="0" class="">写作</dd>
                                    <dd lay-value="1" class="layui-this">阅读</dd>
                                    <dd lay-value="2" class="">游戏</dd>
                                    <dd lay-value="3" class="">音乐</dd>
                                    <dd lay-value="4" class="">旅行</dd>
                                </dl>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="kit-search-footer">
                    <button type="reset" class="layui-btn layui-btn-small layui-btn-primary kit-btn">重置</button>
                    <button lay-submit="" lay-filter="search" class="layui-btn layui-btn-small kit-btn">确定</button>
                </div>
            </div>
        </form>
    </div>

    <table class="layui-table" lay-data="{url:'table.json', page:true, id:'idTest',height: 'full-75'}" lay-filter="test1">
        <thead>
            <tr>
                <th lay-data="{checkbox:true, fixed: true}"></th>
                <th lay-data="{field:'id', width:80, sort: true}">ID</th>
                <th lay-data="{field:'username', width:80}">用户名</th>
                <th lay-data="{field:'sex', width:80, sort: true}">性别</th>
                <th lay-data="{field:'city', width:80}">城市</th>
                <th lay-data="{field:'sign', width:177}">签名</th>
                <th lay-data="{field:'experience', width:80, sort: true}">积分</th>
                <th lay-data="{field:'score', width:80, sort: true}">评分</th>
                <th lay-data="{field:'classify', width:80}">职业</th>
                <th lay-data="{field:'wealth', width:135, sort: true}">财富</th>
                <th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
    </script>

    <script src="./plugins/layui/layui.js"></script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            form = layui.form,
            //监听表格复选框选择
            table.on('checkbox(test1)', function (obj) {
                console.log(obj)
            });
            //监听工具条
            table.on('tool(test1)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layer.msg('ID：' + data.id + ' 的查看操作');
                } else if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    layer.alert('编辑行：<br>' + JSON.stringify(data))
                }
            });

            var $ = layui.$, active = {
                getCheckData: function () { //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        , data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
                , getCheckLength: function () { //获取选中数目
                    var checkStatus = table.checkStatus('idTest')
                        , data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                }
                , isAll: function () { //验证是否全选
                    var checkStatus = table.checkStatus('idTest');
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听搜索表单提交
            form.on('submit(search)', function (data) {
                console.log(data.field);
                layer.msg(JSON.stringify(data.field));
                //带条件查询
                // tableIns.reload({
                //     where: data.field
                // });
                return false;
            });
            
            form.render(null, 'kit-search-form');
            $('#kit-search-more').on('click', function () {
                $('.kit-search-mored').toggle();
            });
            var editIndex;
            form.on('submit(formEdit)', function (data) {
                layer.msg('formEdit');
                editIndex && layer.close(editIndex); //关闭弹出层
                return false;
            });
            
        });
    </script>
    <!-- <script>
        layui.use('table', function () {
            var table = layui.table;
        });
    </script> -->
</body>

</html>